import {request as Request} from "./Ajax";
import API from "./API";
import {showModal} from "../service/Wx";
import {getStorageSync} from "../utils/Storage";
import CustomError from "../utils/CustomError";
let Revisit = {
    /*
    * 获取回访问卷
    * */
    getList: async function () {
        try {
            return await Request({
                url: API.revisitOption
            })
        } catch (e) {
            throw new CustomError (e, "Revisit.getList").parse()
        }
    },


    /*
    * 提交回访问卷
    * */
    saveAnswer: async function (data = {}) {
        try {
            return await Request({
                url: API.revisitSubmit,
                method: "POST",
                data
            })
        } catch (e) {
            throw new CustomError (e, "Revisit.saveAnswer").parse()
        }
    },

    /*
    * 检测是否需要回访
    * */
    checkComplete: async function () {
        try {
            let res =  await Request({
                url: API.revisitValidate,
            })
            if (res.isValidate) {
                await showModal({
                    title: "私募投资基金回访函",
                    content: "根据《基金募集机构投资者适当性管理实施指引（试行）》第十二条的规定，需对客户进行定期回访。请您回答以下几个问题。",
                    showCancel: false,
                    confirmColor: "#b22e2a"
                });
                wx.reLaunch({url: "/packageRevisit/pages/list/index"});
            }
            return res.isValidate
        } catch (e) {
            throw new CustomError (e, "Revisit.checked").parse()
        }
    }
}
module.exports = Revisit